server-functions consistent return between client and server#792
server-functions consistent return between client and server#792arbassett wants to merge 4 commits into
Conversation
| } else if ( | ||
| typeof data === "object" || | ||
| typeof data === "string" || | ||
| typeof data === "number" || | ||
| typeof data === "boolean" | ||
| ) { | ||
| return JSON.stringify(data); |
There was a problem hiding this comment.
This could be optimized to only stringify on object but to make the check consistent with repondWith I left it as is
…server-res-match-client
|
This is a good point. I wonder if we should just use Solid's serializer that we use for resources. We did something simple initially. Actually this probably more relevant for Bling (where we are currently in the process of extracting this into a reusable library) and where this will ultimately land. |
ah now that bling has its own repo ill check that this is handled & create a issue if its not to keep track of it since this will ultimately be a bling issue ill close this and move work there |
fixes #768
server-functions are inconsistent between server renders and client renders.
When the server does a render server$ is directly invoked
and on the client server$ is a fetch to the generate endpoint
So when the server does a SSR render you get a raw Date object back from the server function while on the client its over a network boundary so it gets serialized by the server function middleware. This causes issues when returning none serializable object like Date where on the server you can call
toLocaleDateStringand get a successful first render but when the client navigates to the page it throwsTRPC went though a similar issue with their types trpc/trpc#3261 and what this PR is based on